package com.syg.RateLimiter.controller;

import com.google.common.util.concurrent.RateLimiter;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author oe_shenyiguang
 */
@RestController
public class RateLimiterController {

    Integer i = 1;
    /**
     * 每秒不超过2个任务被提交
     */
    RateLimiter limiter = RateLimiter.create(1);

    @RequestMapping("/rateLimiter")
    public Integer rateLimiter() {
        try {
            Thread.sleep(3000001);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        limiter.acquire();
        System.out.println(++i);
        return i;
    }
}
